﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using CTRL;
using BLL;

namespace GUI.UserControls
{
    public partial class UCListRelease : UserControl
    {
        private CtrlDemos ctrlDemos;
        private List<Record> listRecords;

        public UCListRelease()
        {
            InitializeComponent();

            ctrlDemos = CtrlDemos.Instance;

            listRecords = ctrlDemos.GetLastReleastList();

            PopulateList(listRecords);
        }

        public void PopulateList(List<Record> list)
        {
            listRelease.Items.Clear();
            Imagelist.Images.Clear();

            foreach (var l in list)
            {
                Image img = (l.Jumper.Country.TLD.Equals("n-a")) ? (Image)GUI.Properties.Resources.ResourceManager.GetObject("unknown_flag") : (Image)GUI.Properties.Resources.ResourceManager.GetObject("flag_" + l.Jumper.Country.TLD);

                Imagelist.Images.Add(l.Jumper.Country.TLD, img);
            }

            foreach (var l in list)
            {
                ListViewItem li = new ListViewItem();

                if ((l.Map != null) && l.Jumper != null)
                {
                    li.ImageKey = l.Jumper.Country.TLD;
                    li.Text = l.Jumper.Name;
                    li.SubItems.Add(l.Map.Name);
                    li.SubItems.Add(UTIL.KZTime.ToString(l.Time));
                }

                listRelease.Items.Add(li);
            }

            listRelease.AutoResizeColumns(System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent);
        }

        private void btnDownload_Click(object sender, EventArgs e)
        {
            GUI.UserInterfaces.GUIDemosDownload.ShowForm(listRecords);
        }
    }
}
